#+TITLE: Calculation
#+AUTHOR: Zelphir Kaltstahl
#+STARTUP: content indent align inlineimages hideblocks entitiesplain nologdone nologreschedule nologredeadline nologrefile
#+TODO: TODO WIP | DONE
#+DATE: <2021-05-08 Sa>
#+LANGUAGE: English
#+PRIORITIES: A C C


* Simple arithmetic operations

** Add, multiply, substract

#+begin_src sml
1+2*3-4
#+end_src

#+RESULTS:
: val it = 3 : int

** Divide

#+name: wrong-division
#+begin_src sml :results output verbatim replace drawer
3/4
#+end_src

#+RESULTS: wrong-division
:results:
stdIn:1.2-1.5 Error: operator and operand don't agree [overload conflict]
  operator domain: real * real
  operand:         [int ty] * [int ty]
  in expression:
:end:

Dividing works only on real numbers, not on integers.

But there is integer division as well:

#+name: integer-division
#+begin_src sml :results output verbatim replace drawer
3 div 2
#+end_src

#+RESULTS: integer-division
:results:
val it = 1 : int
:end:


** Modulo

#+begin_src sml
5 mod 2
#+end_src

#+RESULTS:
: val it = 1 : int

** Negative numbers

#+name: negative-numbers
#+begin_src sml :results output verbatim replace drawer
~3+4
#+end_src

#+RESULTS: negative-numbers
:results:
val it = 1 : int
:end:
